package com.ruoyi.classai.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.classai.domain.EwcCourseplanTeaching;
import com.ruoyi.classai.service.IEwcCourseplanTeachingService;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 课时计划教学关联Controller
 * 
 * @author lcj
 * @date 2025-04-12
 */
@RestController
@RequestMapping("/teaching")
public class EwcCourseplanTeachingController extends BaseController
{
    @Autowired
    private IEwcCourseplanTeachingService ewcCourseplanTeachingService;

    /**
     * 查询课时计划教学关联列表
     */
    @RequiresPermissions("system:teaching:list")
    @GetMapping("/list")
    public TableDataInfo list(EwcCourseplanTeaching ewcCourseplanTeaching)
    {
        startPage();
        List<EwcCourseplanTeaching> list = ewcCourseplanTeachingService.list(Wrappers.query(ewcCourseplanTeaching));
        return getDataTable(list);
    }

    /**
     * 导出课时计划教学关联列表
     */
    @RequiresPermissions("system:teaching:export")
    @Log(title = "课时计划教学关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EwcCourseplanTeaching ewcCourseplanTeaching)
    {
        List<EwcCourseplanTeaching> list = ewcCourseplanTeachingService.list(Wrappers.query(ewcCourseplanTeaching));
        ExcelUtil<EwcCourseplanTeaching> util = new ExcelUtil<EwcCourseplanTeaching>(EwcCourseplanTeaching.class);
        util.exportExcel(response, list, "课时计划教学关联数据");
    }

    /**
     * 获取课时计划教学关联详细信息
     */
    @RequiresPermissions("system:teaching:query")
    @GetMapping(value = "/getInfo/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(ewcCourseplanTeachingService.getById(id));
    }

    /**
     * 新增课时计划教学关联
     */
    @RequiresPermissions("system:teaching:add")
    @Log(title = "课时计划教学关联", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody EwcCourseplanTeaching ewcCourseplanTeaching)
    {
        return toAjax(ewcCourseplanTeachingService.save(ewcCourseplanTeaching));
    }

    /**
     * 修改课时计划教学关联
     */
    @RequiresPermissions("system:teaching:edit")
    @Log(title = "课时计划教学关联", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody EwcCourseplanTeaching ewcCourseplanTeaching)
    {
        return toAjax(ewcCourseplanTeachingService.updateById(ewcCourseplanTeaching));
    }

    /**
     * 删除课时计划教学关联
     */
    @RequiresPermissions("system:teaching:remove")
    @Log(title = "课时计划教学关联", businessType = BusinessType.DELETE)
	@GetMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(ewcCourseplanTeachingService.removeByIds(Arrays.asList(ids)));
    }
}
